package cn.gzsf.sboot08.controller;

import cn.gzsf.sboot08.entity.Emp;
import cn.gzsf.sboot08.mapper.EmpMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class EmpController {

    @Autowired
    private EmpMapper mapper;

   @RequestMapping("/insert")
    public void insert(Emp emp){
       System.out.println("emp = " + emp);
       mapper.insert(emp);
   }

   @RequestMapping("/select")
    public List<Emp> select(){
        return  mapper.select();
   }

   @RequestMapping("/delete")
    public void delete(Integer id){
       mapper.deleteById(id);
   }

   @RequestMapping("/selectById")
    public Emp selectById(Integer id){
       return mapper.selectById(id);
   }

    @RequestMapping("/update")
    /*如果前端传过来的是一个js对象，在后端controller方法参数接收时，
    需要方法参数前加一个注解@RequestBody */
    public void update(@RequestBody Emp emp){
       mapper.update(emp);
    }
}
